package com.woniuxy01;

/**
@author 作者
@create 2025-07-28 10:43
*/public class Test02 {
    public static void main(String[] args) {
//        1、5-15位
//        2、都是数字，0不能开头
//        String qqNum="a123456";
//        System.out.println(validateQqNumber(qqNum));
//        //正则表达式
//        System.out.println(qqNum.matches("^[1-9]\\d{4,14}$"));

        //  任意单词字符@任意字符.任意字符
        String email="124242163.com";
//        String emailRegex="^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+";
        String emailRegex="^\\w+@\\w+\\.\\w+$";
        System.out.println(email.matches(emailRegex));

    }

    private static boolean validateQqNumber(String qqNum) {
//        if(qqNum.length()>=5&&qqNum.length()<=15){
//            //继续验证其他规则
//        }else{
//            return false;
//        }

        if(!(qqNum.length()>=5&&qqNum.length()<=15)){
            return false;
        }

        if(qqNum.startsWith("0")){
            return false;
        }

        for(char mychar : qqNum.toCharArray()){
            if(!(mychar>='0' && mychar<='9')){
                return false;
            }
        }

        return true;


    }

    private static void test01() {
        String source="abjavacdejavafghijjavakljava";
        String targe="java";
        int count = getCount(source, targe);
        System.out.println(count);
    }

    private static int getCount(String source, String targe) {
        int count=0,index=-1,fromIndex=0;
        do{
            index= source.indexOf(targe,fromIndex);
            if(index!=-1){
                count++;
//                source=source.substring(index+targe.length());
                fromIndex=index+ targe.length();
            }
        }while(index!=-1);
        return count;
    }


}
